<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 4.57: Capacity of a communication channel</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch04_cvx_opt_probs/html/channel_capacity.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 4.57: Capacity of a communication channel</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Jo&Atilde;&laquo;lle Skaf - 04/24/08</span>
<span class="comment">%</span>
<span class="comment">% We consider a discrete memoryless communication channel, with input</span>
<span class="comment">% X(t) \in {1,...,n}, and output Y(t) \in {1,...,m}, for t = 1,2,...</span>
<span class="comment">% The relation between the input and output is given statistically:</span>
<span class="comment">%           p_ij = Prob(Y(t)=i|X(t)=j), i=1,...,m,  j=1,...,n</span>
<span class="comment">% The matrix P is called the channel transition matrix.</span>
<span class="comment">% The channel capacity C is given by</span>
<span class="comment">%           C = sup{ I(X;Y) | x &gt;= 0, sum(x) = 1},</span>
<span class="comment">% I(X;Y) is the mutual information between X and Y, and it can be shown</span>
<span class="comment">% that:     I(X;Y) = c'*x - sum_{i=1}^m y_i*log_2(y_i)</span>
<span class="comment">% where     c_j = sum_{i=1}^m p_ij*log_2(p_ij), j=1,...,m</span>

<span class="comment">% Input data</span>
rand(<span class="string">'state'</span>, 0);
n = 15;
m = 10;
P = rand(m,n);
P = P./repmat(sum(P),m,1);
c = sum(P.*log2(P))';

<span class="comment">% Channel capacity</span>
cvx_begin
    variable <span class="string">x(n)</span>
    y = P*x;
    maximize (c'*x + sum(entr(y))/log(2))
    x &gt;= 0;
    sum(x) == 1;
cvx_end
C = cvx_optval;

<span class="comment">% Results</span>
display([<span class="string">'The channel capacity is: '</span> num2str(C) <span class="string">' bits.'</span>])
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Successive approximation method to be employed.
   sedumi will be called several times to refine the solution.
   Original size: 45 variables, 21 equality constraints
   10 exponentials add 80 variables, 50 equality constraints
-----------------------------------------------------------------
 Cones  |             Errors              |
Mov/Act | Centering  Exp cone   Poly cone | Status
--------+---------------------------------+---------
 10/ 10 | 2.713e+00  4.909e-01  7.095e-08 | Solved
 10/ 10 | 4.540e-02  1.465e-04  8.655e-08 | Solved
 10/ 10 | 3.971e-03  1.151e-06  8.905e-08 | Solved
  0/ 10 | 2.034e-04  8.980e-08  8.895e-08 | Solved
-----------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.296291
The channel capacity is: 0.29629 bits.
</pre>
</div>
</body>
</html>